// pages/Information/Information.js
var app = getApp();
Page({

  /**
  * 页面的初始数据
  */
  data: {
    // 首页轮播图
    notice: [],
    indicatorDots: true,
    autoplay: true,
    interval: 3000,
    duration: 500,
    dataList: [],
    page: 1,
    allPage: ''
  },

  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {

  },

  /**
  * 生命周期函数--监听页面初次渲染完成
  */
  onReady: function () {

  },

  /**
  * 生命周期函数--监听页面显示
  */
  onShow: function () {
    var that = this;
    var data = {
      paraUrl: 'advertisement/list?position=news&type=banner',
      paraData: ''
    }
    app.getRequest(data, function (res) {
      if (res.data.result == 200) {
        that.setData({
          notice: res.data.body
        });
      }
    })
    that.getList()
  },
  getList(type) {
    var that = this;
    var data = {
      paraUrl: 'information/page?type=news&subtype=&page=' + that.data.page + '&size=5',
      paraData: ''
    }
    app.getRequest(data, function (res) {
      if (res.data.result == 200) {
        if (type == 1) {
          var dataList = that.data.dataList.concat(res.data.body.content)
        } else {
          var dataList = res.data.body.content
        }
        that.setData({
          dataList: dataList,
          allPage: res.data.body.totalPages
        });
      }
    })
  },
  onReachBottom: function (e) {
    var that = this;
    if (that.data.page < that.data.allPage) {
      that.setData({
        page: that.data.page + 1,
      })
      that.onShow(1);
    }
  },
  /**
  * 生命周期函数--监听页面隐藏
  */
  onHide: function () {

  },

  /**
  * 生命周期函数--监听页面卸载
  */
  onUnload: function () {

  },

  /**
  * 页面相关事件处理函数--监听用户下拉动作
  */
  onPullDownRefresh: function () {

  },

  /**
  * 页面上拉触底事件的处理函数
  */
  onReachBottom: function (e) {
    var that = this;
    if (that.data.page < that.data.allPage) {
      that.setData({
        page: that.data.page + 1,
      })
      that.getList(1);
    }
  },

  /**
  * 用户点击右上角分享
  */
  onShareAppMessage: function () {

  },
  tiaozhuan: function (e) {
		wx.setStorageSync('newsContent', e.currentTarget.id);
		// 暂时默认实现url跳转web-view
    wx.navigateTo({
      url: '../out/out'
    })
  }
})